home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / WWW / Perl_WWW_Utilities / perlMIF_beta2 / mif / mif_views.pl < prev    next >
Encoding:
Perl Script  |  1994-05-18  |  6.6 KB  |  214 lines

  1. ##---------------------------------------------------------------------------##
  2. ##  File:
  3. ##      mif_views.pl
  4. ##  Author:
  5. ##      Earl Hood       ehood@convex.com
  6. ##  Description:
  7. ##    This file is defines the "mif_views" perl package.  It defines
  8. ##    routines to handle the Views via MIFread_mif() defined in
  9. ##    the "mif" package.
  10. ##---------------------------------------------------------------------------##
  11. ##  Copyright (C) 1994  Earl Hood, ehood@convex.com
  12. ##
  13. ##  This program is free software; you can redistribute it and/or modify
  14. ##  it under the terms of the GNU General Public License as published by
  15. ##  the Free Software Foundation; either version 2 of the License, or
  16. ##  (at your option) any later version.
  17. ## 
  18. ##  This program is distributed in the hope that it will be useful,
  19. ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ##  GNU General Public License for more details.
  22. ##  
  23. ##  You should have received a copy of the GNU General Public License
  24. ##  along with this program; if not, write to the Free Software
  25. ##  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. ##---------------------------------------------------------------------------##
  27.  
  28. require 'mif/mif.pl' || die "Unable to require mif.pl\n";
  29.  
  30. package mif_views;
  31.  
  32. ##---------------------------------------##
  33. ## Add Views function to %MIFToken array ##
  34. ##---------------------------------------##
  35. $mif'MIFToken{'Views'} = 'Views';
  36.  
  37. ##--------------------------##
  38. ## Views associative arrays ##
  39. ##--------------------------##
  40. %ViewCutout    = ();    # $; separated string of cutout colors
  41. %ViewInvisible    = ();    # $; separated string of hidden colors
  42.  
  43. ##---------------------------------------##
  44. ## Variables for current View definition ##
  45. ##---------------------------------------##
  46. $v_Number    = "";
  47. $v_Cutout    = "";
  48. $v_Invisible    = "";
  49.  
  50. ##------------------------##
  51. ## Import 'mif' variables ##
  52. ##------------------------##
  53. $MStore        = $mif'MStore;
  54. $MOpen        = $mif'MOpen;
  55. $MClose        = $mif'MClose;
  56. $MLine        = $mif'MLine;
  57. $mso        = $mif'mso;
  58. $msc        = $mif'msc;
  59. $stb        = $mif'stb;
  60. $ste        = $mif'ste;
  61. $como        = $mif'como;
  62.  
  63.                 ##---------------##
  64.                 ## Main Routines ##
  65.                 ##---------------##
  66. ##---------------------------------------------------------------------------
  67. ##    MIFwrite_views() outputs the Views as defined by the
  68. ##    associative arrays.
  69. ##
  70. ##    Usage:
  71. ##        &'MIFwrite_views(FILEHANDLE);
  72. ##
  73. sub main'MIFwrite_views {
  74.     local($handle, $l) = @_;
  75.     local($i0, $i1, $i2) = (' ' x $l, ' ' x (1+$l), ' ' x (2+$l));
  76.  
  77.     print $handle $i0, $mso, 'Views', "\n";
  78.     foreach (sort keys %ViewCutout) {
  79.     print $handle $i1, $mso, "View\n";
  80.     print $handle $i2, $mso, 'ViewNumber ', $_, $msc, "\n";
  81.     if ($ViewCutout{$_}) {
  82.         foreach (split(/$;/, $ViewCutout{$_})) {
  83.         print $handle $i2, $mso, 'ViewCutout ', $stb, $_,
  84.                    $ste, $msc, "\n";
  85.         }
  86.     }
  87.     if ($ViewInvisible{$_}) {
  88.         foreach (split(/$;/, $ViewInvisible{$_})) {
  89.         print $handle $i2, $mso, 'ViewInvisible ', $stb,
  90.                    $_, $ste, $msc, "\n";
  91.         }
  92.     }
  93.     print $handle $i1, $msc, " $como end of View\n";
  94.     }
  95.     print $handle $i0, $msc, " $como end of Views\n";
  96. }
  97. ##---------------------------------------------------------------------------##
  98. ##    MIFget_view_data() returns the data associated with the Frame
  99. ##    view $view.
  100. ##
  101. ##    Usage:
  102. ##        ($cutout, $invisible) = &'MIFget_view_data($color);
  103. ##
  104. ##    Note: Return strings contain $; separated values.
  105. ##
  106. sub main'MIFget_view_data {
  107.     local($view) = @_;
  108.     ($ViewCutout{$view}, $ViewInvisible{$view});
  109. }
  110. ##---------------------------------------------------------------------------##
  111. ##    MIFget_views() returns a sorted array of all view numbers defined
  112. ##    in the view catalog.
  113. ##
  114. ##    Usage:
  115. ##        @views = &'MIFget_views();
  116. ##
  117. sub main'MIFget_views {
  118.     return sort keys %ViewCutout;
  119. }
  120. ##---------------------------------------------------------------------------##
  121. ##    MIFreset_views() resets the associative arrays for the views.
  122. ##
  123. ##    Usage:
  124. ##        &'MIFreset_views();
  125. ##
  126. sub main'MIFreset_views {
  127.     undef %ViewCutout;
  128.     undef %ViewInvisible;
  129. }
  130. ##---------------------------------------------------------------------------##
  131.                 ##--------------##
  132.                 ## Mif Routines ##
  133.                 ##--------------##
  134. ##---------------------------------------------------------------------------##
  135. ##    The routines definded below are all registered in the %MIFToken         ##
  136. ##    array for use in the read_mif() routine.  There purpose is to         ##
  137. ##    store the information contained in the views statement.             ##
  138. ##---------------------------------------------------------------------------##
  139.  
  140. ##---------------------------------------------------------------------------
  141. ##    Views() is the token routine for 'Views'.
  142. ##    It sets/restores token routines depending upon mode.
  143. ##
  144. sub mif'Views {
  145.     local($token, $mode, *data) = @_;
  146.     if ($mode == $MOpen) {
  147.     ($_fast, $_noidata) = ($mif'fast, $mif'no_import_data);
  148.     ($mif'fast, $mif'no_import_data) = (1, 1);
  149.     @_v_orgfunc = @mif'MIFToken{
  150.                 'View',
  151.                 'ViewNumber',
  152.                 'ViewCutout',
  153.                 'ViewInvisible'
  154.             };
  155.     @mif'MIFToken{
  156.         'View',
  157.         'ViewNumber',
  158.         'ViewCutout',
  159.         'ViewInvisible'
  160.     } = (
  161.         "mif_views'View",
  162.         "mif_views'ViewNumber",
  163.         "mif_views'ViewCutout",
  164.         "mif_views'ViewInvisible"
  165.     );
  166.     } elsif ($mode == $MClose) {
  167.     @mif'MIFToken{
  168.         'View',
  169.         'ViewNumber',
  170.         'ViewCutout',
  171.         'ViewInvisible'
  172.     } = @_v_orgfunc;
  173.         ($mif'fast, $mif'no_import_data) = ($_fast, $_noidata);
  174.     }
  175. }
  176. ##---------------------------------------------------------------------------
  177. sub View {
  178.     local($token, $mode, *data) = @_;
  179.  
  180.     if ($mode == $MOpen) {
  181.     $v_Number = "";
  182.     $v_Cutout = "";
  183.     $v_Invisible = "";
  184.     } elsif ($mode == $MClose) {
  185.     $ViewCutout{$v_Number} = $v_Cutout;
  186.     $ViewInvisible{$v_Number} = $v_Invisible;
  187.     } else {
  188.     warn "Unexpected mode, $mode, passed to View routine\n";
  189.     }
  190. }
  191. ##---------------------------------------------------------------------------
  192. sub ViewCutout {
  193.     local($token, $mode, *data) = @_;
  194.     local($tmp);
  195.     $v_Cutout .= $; if $v_Cutout ne "";
  196.     ($tmp) = $data =~ /^\s*$stb([^$ste]*)$ste.*$/o;
  197.     $v_Cutout .= $tmp;
  198. }
  199. ##---------------------------------------------------------------------------
  200. sub ViewInvisible {
  201.     local($token, $mode, *data) = @_;
  202.     local($tmp);
  203.     $v_Invisible .= $; if $v_Invisible ne "";
  204.     ($tmp) = $data =~ /^\s*$stb([^$ste]*)$ste.*$/o;
  205.     $v_Invisible .= $tmp;
  206. }
  207. ##---------------------------------------------------------------------------
  208. sub ViewNumber {
  209.     local($token, $mode, *data) = @_;
  210.     ($v_Number) = $data =~ /^\s*(.*)$/o;
  211. }
  212. ##---------------------------------------------------------------------------
  213. 1;
  214.